-
-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(config): allow user custom .env files directory #2123
Conversation
@@ -268,7 +274,10 @@ export async function resolveConfig( | |||
} | |||
|
|||
// load .env files | |||
const userEnv = loadEnv(mode, resolvedRoot) | |||
const envDir = config.envDir | |||
? normalizePath(path.resolve(config.envDir)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
? normalizePath(path.resolve(config.envDir)) | |
? normalizePath(path.resolve(resolvedRoot, config.envDir)) |
- **Type:** `string` | ||
- **Default:** `root` | ||
|
||
Environment files directory. Can be an absolute path, or a path relative from the location of the config file itself. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably worth adding a link to the .env
guide:
See [here](/guide/env-and-mode#env-files) for more about environment files.
+1, very useful when you have a multi-project workspace and want to keep a top-level Would be great to have this merged, thank you =) |
@GavinRay97 Agreed. Do you want to fork this PR and add the suggested changes so we can merge? |
Sure np, can do it today after work 👍 |
Btw, this is how I am working around this now. // vite.config.ts
import reactRefresh from "@vitejs/plugin-react-refresh"
import * as dotenv from "dotenv"
import { defineConfig } from "vite"
const result = dotenv.config({
debug: true,
path: require("path").join(__dirname, "../.env"),
})
if (result.error) throw result.error
const defines = {}
for (let key in result.parsed) {
if (!key.startsWith("VITE_")) continue
defines["import.meta.env." + key] = JSON.stringify(result.parsed[key])
}
export default defineConfig({
plugins: [reactRefresh()],
define: defines,
}) |
Close #2113